package DAO;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.criterion.Criterion;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;
import org.hibernate.impl.CriteriaImpl.CriterionEntry;

import to.Configuracao;
import to.Endereco;
import to.Funcionario;
import to.Laboratorio;
import to.Laboratorio;
import to.Pessoa;
import to.Usuario;
import util.ConnectionFactory;
import util.HibernateUtil;

public class LaboratorioDAO {

	public List<Laboratorio> buscaTodos() throws Exception {
		List<Laboratorio> listaRetorno = null;
		try {
			Session session = HibernateUtil.getSessionFactory().openSession();
			Criteria criteria = session.createCriteria(Laboratorio.class);
			criteria.addOrder(Order.asc("descricao"));
			listaRetorno = (List<Laboratorio>) criteria.list();
		} catch (Exception e) {
			throw new Exception(e.getMessage());
		}
		return listaRetorno;
	}
	public Laboratorio pesquisarPorCodigo(Integer codigo) throws Exception{
		Laboratorio laboratorio = null;
		try {
			Session session = HibernateUtil.getSessionFactory().openSession();
			laboratorio = (Laboratorio) session.get(Laboratorio.class, codigo);
		} catch (Exception e) {
			throw new Exception(e.getMessage());
		}	
		return laboratorio;
	}
}
